package com.hawk.eye.server.convert;

import com.hawk.eye.common.model.TemplateNode;
import com.hawk.eye.server.domain.dto.req.TemplateReqDTO;
import com.hawk.eye.server.domain.dto.resp.TemplateRespDTO;
import com.hawk.eye.server.domain.vo.req.TemplateReqVO;
import com.hawk.eye.server.domain.vo.resp.TemplateRespVO;
import org.mapstruct.DecoratedWith;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;

import java.util.ArrayList;
import java.util.List;

/**
 * @author zd
 */
@Mapper
@DecoratedWith(TemplateConvert.TemplateConvertDecorator.class)
public interface TemplateConvert {

    TemplateConvert INSTANCE = Mappers.getMapper(TemplateConvert.class);

    List<TemplateRespVO> to(List<TemplateRespDTO> templates);


    List<TemplateRespDTO> to2(List<TemplateNode> templates);

    TemplateRespVO to(TemplateRespDTO template);


    TemplateReqDTO to(TemplateReqVO reqVO);

    public abstract class TemplateConvertDecorator implements TemplateConvert{

        @Override
        public List<TemplateRespVO> to(List<TemplateRespDTO> templates) {
            if (templates == null){
                return null;
            }
            List<TemplateRespVO> list = new ArrayList<>();
            for (TemplateRespDTO template : templates) {
                list.add(to(template));
            }
            return list;
        }
    }

}